home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2006 September / SAN CD 9-2006 CD-ROM 16.iso / pc / Software / Network Telescope Control / NTC-Setup.Exe / Source / ntc_ciel_client_focus.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2006-03-24  |  7.7 KB  |  363 lines

  1. unit ntc_ciel_client_focus;
  2. {
  3.     Copyright (C) 2004 - 2006 Andrew Sprott
  4.  
  5.     http://astronomy.crysania.co.uk
  6.     astro@trefach.co.uk
  7.  
  8.     This program is free software; you can redistribute it and/or
  9.     modify it under the terms of the GNU General Public License
  10.     as published by the Free Software Foundation; either version 2
  11.     of the License, or (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. }
  22.  
  23. interface
  24.  
  25. uses
  26.     Windows,
  27.     Messages,
  28.     SysUtils,
  29.     Variants,
  30.     Classes,
  31.     Graphics,
  32.     Controls,
  33.     Forms,
  34.     Dialogs,
  35.     Buttons,
  36.     StdCtrls,
  37.     ExtCtrls,
  38.     inifiles,
  39.  
  40.     ntc_ciel_client_form,
  41.     ntc_ciel_client_network;
  42.  
  43. const
  44.     default_timeout=500;
  45.  
  46. type
  47.     Tscope_focus = class(tform)
  48.         focus_panel: TPanel;
  49.         focus_minus_button: TSpeedButton;
  50.         focus_plus_button: TSpeedButton;
  51.         speed_label: TLabel;
  52.         speed_box: TPanel;
  53.         first_speed_button: TSpeedButton;
  54.         timeout_duration_label: TLabel;
  55.         millisecond_label: TLabel;
  56.         timeout_duration_edit: TEdit;
  57.         stop_button: TSpeedButton;
  58.         focus_timer: TTimer;
  59.  
  60.         { form functions }
  61.         procedure formcreate(
  62.             Sender:TObject);
  63.  
  64.         procedure form_close_query(
  65.                     Sender: TObject;
  66.             var CanClose: Boolean);
  67.  
  68.         procedure flip_buttons(
  69.             toggle:boolean);
  70.  
  71.         { communications }
  72.         function send_request_check(
  73.             m:string)
  74.             :response_type;
  75.  
  76.         { configuration }
  77.         procedure load_settings;
  78.  
  79.         procedure save_settings;
  80.  
  81.         { events }
  82.         procedure FormShow(
  83.             Sender: TObject);
  84.  
  85.         procedure adjust;
  86.  
  87.         procedure check_activate(
  88.             Sender: TObject);
  89.  
  90.         procedure speed_button_click(
  91.             Sender: TObject);
  92.  
  93.         procedure stop_buttonClick(
  94.             Sender: TObject);
  95.  
  96.         procedure focus_minus_buttonClick(
  97.             Sender: TObject);
  98.  
  99.         procedure focus_plus_buttonClick(
  100.             Sender: TObject);
  101.  
  102.         procedure enable_focus_timer;
  103.  
  104.         procedure focus_timerTimer(
  105.             Sender: TObject);
  106.  
  107.         procedure timeout_duration_editChange(
  108.             Sender: TObject);
  109.  
  110.     private
  111.         { Private declarations }
  112.         speed_group_index:integer;
  113.     public
  114.         { Public declarations }
  115.         focus_speeds,
  116.         start_focus_speed:integer;
  117.         can_focus:boolean;
  118.         focus_timeout:integer;
  119.         { configuration }
  120.         dimensions:dimensions_record;
  121.  
  122.         { events }
  123.         procedure check_visible_and_show_hide(
  124.             sender:tobject);
  125.  
  126.         procedure hide_form;
  127.         procedure show_form;
  128.     end;
  129.  
  130. var
  131.     scope_focus: Tscope_focus;
  132.  
  133. implementation
  134.  
  135. uses
  136.     ntc_ciel_client_control;
  137.  
  138. {$R *.dfm}
  139.  
  140.     { --------------
  141.         form functions
  142.         -------------- }
  143.  
  144. procedure Tscope_focus.formcreate(
  145.     Sender:TObject);
  146. begin
  147.     speed_group_index:=1;
  148.     can_focus:=false;
  149.     flip_buttons(false);
  150.     load_settings;
  151.     visible:=false;
  152. end;
  153.  
  154. procedure tscope_focus.form_close_query(
  155.             Sender: TObject;
  156.     var CanClose: Boolean);
  157. begin
  158.     visible:=false;
  159.     with dimensions do
  160.         begin
  161.             form_top:=top;
  162.             form_left:=left;
  163.         end;
  164.     if ciel_closing then
  165.         canclose:=true
  166.     else
  167.         canclose:=false;
  168. end;
  169.  
  170.     { ---------
  171.         utilities
  172.         --------- }
  173.  
  174. function tscope_focus.send_request_check(
  175.     m:string)
  176.     :response_type;
  177. begin
  178.     result:=scope_network.send_request_check(m);
  179. end;
  180.  
  181. procedure Tscope_focus.flip_buttons(
  182.     toggle:boolean);
  183. begin
  184.     millisecond_label.enabled:=toggle;
  185.     focus_minus_button.enabled:=toggle;
  186.     focus_plus_button.enabled:=toggle;
  187.     timeout_duration_edit.enabled:=toggle;
  188.     speed_label.enabled:=toggle;
  189.     speed_box.enabled:=toggle;
  190.     first_speed_button.enabled:=toggle;
  191.     stop_button.enabled:=toggle;
  192. end;
  193.  
  194.     { -------------
  195.         focus control
  196.         ------------- }
  197.  
  198. procedure Tscope_focus.stop_buttonClick(
  199.     Sender: TObject);
  200. begin
  201.     send_request_check('stop_focus');
  202.     focus_timer.enabled:=false;
  203. end;
  204.  
  205.     { -------------
  206.         configuration
  207.         ------------- }
  208.  
  209. procedure tscope_focus.load_settings;
  210. begin
  211.     ini_file:=tinifile.create(application_path+'ciel.ini');
  212.     with ini_file do
  213.         begin
  214.             can_focus:=ReadBool('focus','can_focus',false);
  215.             focus_timeout:=readinteger('focus','timeout',default_timeout);
  216.             timeout_duration_edit.text:=inttostr(focus_timeout);
  217.             start_focus_speed:=readinteger('focus','start_focus_speed',1);
  218.             focus_speeds:=readinteger('focus','focus_speeds',2);
  219.             if (focus_speeds>9) or
  220.                  (focus_speeds<2) then
  221.                 focus_speeds:=2;
  222.             { form }
  223.             scope.get_dimensions(scope_focus,@dimensions,'focus',ini_file);
  224.             left:=dimensions.form_left;
  225.             top:=dimensions.form_top;
  226.             visible:=readbool('focus','visible',false);
  227.         end;
  228.     ini_file.free;
  229. end;
  230.  
  231. procedure tscope_focus.save_settings;
  232. begin
  233.     with ini_file do
  234.         begin
  235.             writeBool('focus','can_focus',can_focus);
  236.             writeinteger('focus','timeout',focus_timeout);
  237.             writeinteger('focus','start_focus_speed',start_focus_speed);
  238.             writeinteger('focus','focus_speeds',focus_speeds);
  239.             { form }
  240.             scope.find_vdu(scope_focus,@dimensions);
  241.             scope.write_dimensions(@dimensions,left,top,'focus',ini_file);
  242.             writebool('focus','visible',visible);
  243.         end;
  244. end;
  245.  
  246.     { ------
  247.         events
  248.         ------ }
  249.  
  250. procedure Tscope_focus.FormShow(
  251.     Sender: TObject);
  252. begin
  253.     with dimensions do
  254.         begin
  255.             top:=form_top;
  256.             left:=form_left;
  257.         end;
  258.     scope_control.update_speed_group(
  259.         speed_box,
  260.         first_speed_button,
  261.         start_focus_speed,
  262.         focus_speeds,
  263.         speed_button_click,
  264.         can_focus);
  265. end;
  266.  
  267. procedure tscope_focus.adjust;
  268. begin
  269.     with dimensions do
  270.         begin
  271.             form_top:=trunc(form_top/last_screen_height*current_height);
  272.             form_left:=trunc(form_left/last_screen_width*current_width);
  273.         end;
  274.     if visible then
  275.         show;
  276. end;
  277.  
  278. procedure tscope_focus.check_visible_and_show_hide(
  279.     sender:tobject);
  280. begin
  281.     if visible then
  282.         hide_form
  283.     else
  284.         show_form;
  285.     scope.show_hide(sender,visible);
  286. end;
  287.  
  288. procedure tscope_focus.hide_form;
  289. begin
  290.     with dimensions do
  291.         begin
  292.             form_top:=top;
  293.             form_left:=left;
  294.         end;
  295.     Visible:=false;
  296.     formstyle:=fsnormal;
  297. end;
  298.  
  299. procedure tscope_focus.show_form;
  300. begin
  301.     formstyle:=fsstayontop;
  302.     Visible:=true;
  303. end;
  304.  
  305. procedure Tscope_focus.check_activate(
  306.     Sender: TObject);
  307. begin
  308.     scope.form_activate(scope_focus,@dimensions);
  309. end;
  310.  
  311. procedure Tscope_focus.speed_button_click(
  312.     Sender: TObject);
  313. begin
  314.     speed_group_index:=scope_control.set_slew_speed(speed_box);
  315. end;
  316.  
  317. procedure Tscope_focus.focus_minus_buttonClick(
  318.     Sender: TObject);
  319. begin
  320.     if (scope_type=autostar_type) or (scope_type=lx200_type) then
  321.          send_request_check('focus(speed='+inttostr(speed_group_index)+
  322.         ',dir=-,timeout='+inttostr(focus_timeout)+')');
  323. end;
  324.  
  325. procedure Tscope_focus.focus_plus_buttonClick(
  326.     Sender: TObject);
  327. begin
  328.     if (scope_type=autostar_type) or (scope_type=lx200_type) then
  329.          send_request_check('focus(speed='+inttostr(speed_group_index)+
  330.         ',dir=+,timeout='+inttostr(focus_timeout)+')');
  331. end;
  332.  
  333. procedure tscope_focus.enable_focus_timer;
  334. begin
  335.     focus_timer.interval:=focus_timeout;
  336.     focus_timer.enabled:=true;
  337. end;
  338.  
  339. procedure Tscope_focus.focus_timerTimer(
  340.     Sender: TObject);
  341. begin
  342.     focus_timer.enabled:=false;
  343.     if not (send_request_check('stop_focus')>=[exit_ok]) then
  344.         begin
  345.             scope_control.write_status_log('Unable to stop focus');
  346.             focus_timer.interval:=focus_timeout;
  347.             focus_timer.enabled:=true;
  348.         end;
  349. end;
  350.  
  351. procedure Tscope_focus.timeout_duration_editChange(
  352.     Sender: TObject);
  353. begin
  354.     focus_timeout:=strtointdef(timeout_duration_edit.text,default_timeout);
  355.     if focus_timeout<0 then
  356.         begin
  357.             focus_timeout:=default_timeout;
  358.             timeout_duration_edit.text:=inttostr(focus_timeout);
  359.         end;
  360. end;
  361.  
  362. end.
  363.